package com.example.gbasedemo.service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.gbasedemo.mapper.TestMapper;
import com.example.gbasedemo.mapper.TestPojo;
import com.example.gbasedemo.mapper.TradeBaseMapper;
import com.example.gbasedemo.mapper.TradeBasePojo;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;

@Service
public class ServiceTradeBase extends ServiceImpl<TradeBaseMapper, TradeBasePojo> {

    int index = 1;

    public void createTable() {
        baseMapper.createTable();
    }

    public void insert() {
        TradeBasePojo pojo = new TradeBasePojo();
        pojo.setId(index); index++;
        pojo.setFiled_a(12345);
        pojo.setFiled_b("v filed_b");
        pojo.setFiled_c("v filed_c");
        pojo.setFiled_d("v filed_d");
        pojo.setFiled_e("v filed_e");
        pojo.setFiled_f("v filed_f");
        pojo.setFiled_g("v filed_g");
        pojo.setFiled_h("v filed_h");
        pojo.setFiled_i("v filed_i");
        pojo.setFiled_j("v filed_j");
        pojo.setYn(888);
        pojo.setCreate_time(new Timestamp(System.currentTimeMillis()));
        pojo.setUpdate_time(new Timestamp(System.currentTimeMillis()));
        pojo.setExt_1("ext 1");
        pojo.setExt_2("ext 2");
        pojo.setExt_3("ext 3");
        baseMapper.insert(pojo);
    }

    public void updateRow() {
        TradeBasePojo pojo = getPojo(1);
        pojo.setExt_3("ext33333333333");
        baseMapper.updateById(pojo);
    }

    public void deleteRow() {
        baseMapper.deleteById(1);
    }

    public void insertRows() {
        List<TradeBasePojo> rows = new ArrayList<>();
        for (int i=100; i<=102; i++) {
            TradeBasePojo pojo = getPojo(i);
            rows.add(pojo);
        }
        baseMapper.insertRows(rows);
    }

    private TradeBasePojo getPojo(int index) {
        TradeBasePojo pojo = new TradeBasePojo();
        pojo.setId(index);
        pojo.setFiled_a(index * 10);
        pojo.setFiled_b(index + "v filed_b");
        pojo.setFiled_c(index + "v filed_c");
        pojo.setFiled_d(index + "v filed_d");
        pojo.setFiled_e(index + "v filed_e");
        pojo.setFiled_f(index + "v filed_f");
        pojo.setFiled_g(index + "v filed_g");
        pojo.setFiled_h(index + "v filed_h");
        pojo.setFiled_i(index + "v filed_i");
        pojo.setFiled_j(index + "v filed_j");
        pojo.setYn(index * 100);
        pojo.setCreate_time(new Timestamp(System.currentTimeMillis()));
        pojo.setUpdate_time(new Timestamp(System.currentTimeMillis()));
        pojo.setExt_1(index + "ext 1");
        pojo.setExt_2(index + "12ext 2");
        pojo.setExt_3(index + "12ext 3");
        return pojo;
    }

}
